.PHONY: clean

CC = gcc
MAKE = make
MKDIR = mkdir

EXE = main
ROOT_DIR = $(shell pwd)
DIR_OBJS = $(ROOT_DIR)/obj
DIR_BIN = $(ROOT_DIR)/bin
DIR_SRC = $(ROOT_DIR)/src
DIRS = $(DIR_OBJS) $(DIR_BIN)

EXE := $(addprefix $(DIR_BIN)/, $(EXE))

OBJS =
export CC ROOT_DIR DIR_OBJS DIR_BIN DIR_SRC OBJS

all: $(DIRS) $(DIR_SRC) get_objs $(EXE)

$(DIRS):
	$(MKDIR) -p $@

$(EXE): 
	$(CC) $(OBJS) -o $@

get_objs: 
	$(eval OBJS := $(shell find $(DIR_OBJS) -name "*.o"))

$(DIR_SRC): ECHO
	$(MAKE) -C $@

ECHO:
	@echo $(DIR_SRC)

clean:
	rm -rf $(DIR_OBJS) $(DIR_BIN)
